package com.dahua.messagesyncsh;

import com.dahua.messagesyncsh.rabbitmq.consumer.Hitachi485Runnable;
import com.dahua.messagesyncsh.service.CollectionService;
import com.dahua.messagesyncsh.service.EquipmentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

import static com.dahua.messagesyncsh.common.Constants.IS_INITIALIZE;

@Slf4j
@Component
public class InitializeRunner implements ApplicationRunner {

    @Value("${schedule.sec-launch}")
    private String secLaunch;

    @Value("${schedule.hitachi485-launch}")
    private String hitachiLaunch;

    @Resource
    private EquipmentService equipmentService;

    @Resource
    private CollectionService collectionService;


    @Resource
    private Hitachi485Runnable hitachi485Runnable;

    @Override
    public void run(ApplicationArguments args) {
        this.cachePreheating();
    }

    public void cachePreheating() {
        equipmentService.caching();

        collectionService.caching();

        IS_INITIALIZE = true;

        /*  日立*/
        if (Boolean.parseBoolean(hitachiLaunch)){
            hitachi485Runnable.run();
        }

        log.info("初始化完成");
    }
}